//
//  LKMainTabBarController.swift
//  weiBo
//
//  Created by Lukj on 2017/3/26.
//  Copyright © 2017年 lukj. All rights reserved.
//

import UIKit

class LKMainTabBarController: UITabBarController, LKTabBarDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        let button = LKTabBar()
        //  设置代理
        button.lkdelegate = self
        button.composeButtonActionClosure = {
            print("我是闭包")
        }
        
        
        
        self.setValue(button, forKey: "tabBar")
        
        addChildViewController(childController: LKHomeTableViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(childController: LKMessageTableViewController(), imageName: "tabbar_message_center", title: "信息")
        addChildViewController(childController: LKDiscoverTableViewController(), imageName: "tabbar_discover", title: "搜索")
        addChildViewController(childController: LKMineTableViewController(), imageName: "tabbar_profile", title: "我的")
        
        
    }

    func addChildViewController(childController: UIViewController, imageName: String, title:String) {
        
        //  设置tabBarItem的图片
        childController.tabBarItem.image = UIImage(named: imageName)
        //  设置tabBarItem的选中图片, 并设置渲染模式使用原始图片方式显示
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(.alwaysOriginal)
        //  设置文字颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: .selected)
        //  设置文字大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 12)], for: .normal)
        //  设置tabBarItem的文字
//        childController.tabBarItem.title = title
//        childController.navigationItem.title = title
        childController.title = title
        
        let nav = LKNavgationController.init(rootViewController: childController)
        
        addChildViewController(nav)
        
    }
    
    
    // MARK: ---LKTabBarDelegate
    func didComposeButton() {
        print("我是代理")
    }
    
    
}
